var OverViewManaged = function() {
	return {

		// 入保电梯数据
		initTotalInsuredOrder : function() {
			var params = {
				state : 4,
			}
			$.ajax({
				"dataType" : 'json', // 接受数据格式
				"type" : "POST", // 数据发送方式
				"data" : params,
				"url" : ctx + "/overView/totalInsuredOrder",
				"success" : function(data) {
					if (data.type == "success") {
						var title = "入保电梯数据一览";
						var myChart = echarts.init(document.getElementById('totalInsuredOrder'));
						OverViewManaged.setPieChartsData(data.data, title, myChart);
					}
				}
			})
		},
		//近期入保电梯数据
		initRecentlyInsuredOrder : function() {
			var params = {
				state : 4,
			}
			$.ajax({
				"dataType" : 'json', // 接受数据格式
				"type" : "POST", // 数据发送方式
				"data" : params,
				"url" : ctx + "/overView/recentlyInsuredOrder",
				"success" : function(data) {
					if (data.type == "success") {
						var title = "近期入保电梯数据一览";
						var myChart = echarts.init(document.getElementById('recentlyInsuredOrder'));
						OverViewManaged.setPieChartsData(data.data, title, myChart);
					}
				}
			})
		},
		//预警入保电梯数据
		initWarningInsuredOrder : function() {
			var params = {
				state : 4,
			}
			$.ajax({
				"dataType" : 'json', // 接受数据格式
				"type" : "POST", // 数据发送方式
				"data" : params,
				"url" : ctx + "/overView/warningInsuredOrder",
				"success" : function(data) {
					if (data.type == "success") {
						var title = "预警入保电梯数据一览";
						var myChart = echarts.init(document.getElementById('warningInsuredOrder'));
						OverViewManaged.setPieChartsData(data.data, title, myChart);
					}
				}
			})
		},
		// 处理饼形图数据
		setPieChartsData : function(data, title, myChart) {
			var legendData = [];
			var pieChartsData = data.insuredOrderList;
			for (var i = 0; i < pieChartsData.length; i++) {
				legendData[i] = pieChartsData[i].name;
			}
			var seriesData = [];
			var seriesObject = new Object();
			seriesObject.name = "电梯类型";
			seriesObject.type = "pie";
			seriesObject.radius = "60%";
			seriesObject.center = [ '50%', '60%' ];
			seriesObject.data = [];// 数据数组
			var dataList = new Object();
			for (var j = 0; j < pieChartsData.length; j++) {
				var obj = new Object();
				obj.value = pieChartsData[j].elevatorNum;
				obj.name = pieChartsData[j].name;
				seriesObject.data[j] = obj;
			}
			seriesData = seriesObject;
			OverViewManaged.viewPieChartsData(legendData, seriesData, title, myChart)
		},
		// 饼形图填充数据
		viewPieChartsData : function(legendData, seriesData, title, myChart) {
			var option = {
				title : {
					text : title,
					subtext : '',
					x : 'left'
				},
				tooltip : {
					trigger : 'item',
					formatter : "{a} <br/>{b} : {c} ({d}%)"
				},
				legend : {
					orient : 'vertical',
					left : 'right',
					data : legendData
				},
				series : seriesData
			};
			// 为echarts对象加载数据
			myChart.setOption(option);
		},

		/**
		 * 平台月度保险交易额一览
		 */
		initPlatformMonthlyData : function() {
			var params = {
				state : 4,
			}
			$.ajax({
				"dataType" : 'json', // 接受数据格式
				"type" : "POST", // 数据发送方式
				"data" : params,
				"url" : ctx + "/overView/platformMonthlyData",
				"success" : function(data) {
					if (data.type == "success") {
						var title = "平台月度保险交易额一览";
						var myChart = echarts.init(document.getElementById('platformMonthlyData'));
						OverViewManaged.setHistogramChartsData(data.data, title, myChart);
					}
				}
			})
		},
		//处理柱状图数据
		setHistogramChartsData : function(data, title, myChart) {
			var xAxisData = [];
			var barChartsData = data.platformMonthlyList;
			for (var i = 0; i < barChartsData.length; i++) {
				xAxisData[i] = barChartsData[i].createDate;
			}
			var seriesData = [];
			var seriesObject = new Object();
			seriesObject.name = "交易额";
			seriesObject.type = "bar";
			seriesObject.barWidth = '40%', seriesObject.data = [];// 数据数组
			var dataList = new Object();
			for (var j = 0; j < barChartsData.length; j++) {
				var obj = new Object();
				obj.value = barChartsData[j].orderAmount;
				seriesObject.data[j] = obj;
			}
			seriesData = seriesObject;
			OverViewManaged.viewBarChartsData(xAxisData, seriesData, title, myChart)
		},
		viewBarChartsData : function(xAxisData, seriesData, title, myChart) {
			var option = {
				title : {
					text : title,
					subtext : '',
					x : 'center'
				},
				color : [ '#3398DB' ],
				tooltip : {
					trigger : 'axis',
					axisPointer : { // 坐标轴指示器，坐标轴触发有效
						type : 'shadow' // 默认为直线，可选为：'line' | 'shadow'
					}
				},
				grid : {
					left : '3%',
					right : '4%',
					bottom : '3%',
					containLabel : true
				},
				xAxis : [ {
					type : 'category',
					data : xAxisData,
					axisTick : {
						alignWithLabel : true
					}
				} ],
				yAxis : [ {
					type : 'value'
				} ],
				series : seriesData
			};
			myChart.setOption(option);
		}

	}
}();